<template>
  <t-dialog :header="`${header} 审批、评审记录`" :visible.sync="visible" :onClose="closeDialog" :closeOnOverlayClick="false"
    :confirmBtn="null" width="80%" top="5%">
    <div style="height: 65vh">
      <t-tabs v-model="tabValue" @change="handleChange">
        <t-tab-panel value="1" label="审批记录" :destroyOnHide="true">
          <t-table rowKey="id" :data="data" :columns="columns" hover :loading="dataLoading">
            <template #approveType="{ row }">
              {{ row.approveType | filterByDict(dict.type.kpzh_approve_type) }}
            </template>
            <template #approveStatus="{ row }">
              <t-tag v-if="row.approveStatus" :theme="handleTheme(row.approveStatus, dict.type.approve_status)"
                variant="light">
                {{ row.approveStatus | filterByDict(dict.type.approve_status) }}
              </t-tag>
              <t-tag v-else theme="warning" variant="light">待审批
              </t-tag>
            </template>
          </t-table>
        </t-tab-panel>
      </t-tabs>
    </div>
  </t-dialog>
</template>

<script>
import { getFiles } from "@/api/common";

export default {
  name: "approve-list",
  dicts: ["prof_tit", "duty", "recommend_type", "kpzh_approve_type", "approve_status", "approve_type", "subject_classification", "kjxm_ys_review_status"],
  components: {

  },
  props: ['header', "objId", "projectName", "reportTrialId"],
  data () {
    return {
      site_tag: import.meta.env.VITE_SITE_TAG,
      psYjsFilesNow: [],
      data3: [],
      tabValue: "1",
      dialog: {
        objId: 0,
        teamId: 0,
        open: false,
        reviewType: null,
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approveType: '',
        businessName: '',
      },
      visible: true,
      data: [],
      columns: [
        // {
        //   colKey: "businessId",
        //   title: "业务id",
        //   align: "center"
        // },
        {
          colKey: "businessName",
          title: "业务名称",
          align: "center",
          ellipsis: true
        },
        {
          colKey: "approveType",
          title: "审批业务类型",
          align: "center",
          ellipsis: true
        },
        {
          colKey: "approverName",
          title: "审批人",
          align: "center",
          ellipsis: true
        },
        {
          colKey: "deptName",
          title: "单位",
          align: "center",
        },
        {
          colKey: "opinion",
          title: "审批意见",
          align: "center",
          ellipsis: true
        },
        {
          colKey: "approveStatus",
          title: "审批结果",
          align: "center",
        },
        {
          colKey: "updateTime",
          title: "审批时间",
          align: "center",
          width: 200
        },
      ],

      dataLoading: false,
      data4: [],

      data2: [],
      // data2:[],
      // data2:[],
      columns2: [
        {
          colKey: "id",
          title: "专家序号",
          align: "center",
          width: 100,
        },
        // {
        //   colKey: "experts.sysUser.dept.deptName",
        //   title: "所在单位",
        //   align: "center"
        // },
        // {colKey: 'experts.sysUser.duty', title: '职务/职称',align: "center"},
        // // {colKey: 'experts.profTit', title: '职称',align: "center"},
        // {colKey: 'experts.sysUser.majorName', title: '专业',align: "center"},
        // {colKey: 'experts.sysUser.majorNowName', title: '现从事专业',align: "center"},
        // {
        //   colKey: "experts.sysUser.education",
        //   title: "学历",
        //   align: "center",
        //   ellipsis: true
        // },
        // {
        //   colKey: "experts.sysUser.degree",
        //   title: "学位",
        //   align: "center",
        //   ellipsis: true
        // },
        { colKey: 'reviewStatus', title: '评审状态', align: "center", width: 100 },
        { colKey: 'score', title: '评审分数', align: "center", width: 100 },
        { colKey: 'content', title: '评审意见', align: "center", width: 300 },
        { colKey: 'sysAttMainEntities', title: '评审附件', align: "center", width: 120 },
        // {colKey: 'projectApproval', title: '是否通过',align: "center"},
        { colKey: 'recommendType', title: '是否推荐', align: "center", width: 100 },
        // {
        //   colKey: "op",
        //   title: "操作",
        //   align: "center"
        // },
      ],
      columns3: [
        {
          colKey: "id",
          title: "专家序号",
          align: "center",
          width: 100,
        },
        { colKey: 'reviewStatus', title: '评审状态', align: "center", width: 100 },
        { colKey: 'content', title: '评审意见', align: "center", width: 300 },
        { colKey: 'sysAttMainEntities', title: '评审附件', align: "center", width: 120 },
        // {colKey: 'score', title: '评审分数',align: "center"},
        // {colKey: 'projectApproval', title: '是否通过',align: "center"},
        { colKey: 'projectApproval', title: '是否通过', align: "center", width: 100 },
      ],
      reviewGroupRecord: null,
    }
  },
  async created () {
    this.getList();
    this.getKjcReply();
    this.getReviewList();
  },
  methods: {
    handleChange (val) {
      this.reviewGroupRecord = null;
      this.getKjcReply();
      this.getReviewList();
    },
    getKjcReply () {
      if (Number(this.tabValue) > 1) {
        this.$api.kpzh.review.projectReviewTeamGetByBusinessIdAndReviewType({
          businessId: this.objId,
          reviewType: (Number(this.tabValue) - 1).toString(),
        }).then(res => {
          this.reviewGroupRecord = res.data;
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }
    },
    getReviewList () {
      this.data2 = [];
      if (Number(this.tabValue) > 1) {
        this.$api.kpzh.review.projectExpertsInfoByReviewType({
          projectId: this.objId,
          reviewType: (Number(this.tabValue) - 1).toString(),
        }).then(response => {
          this.data2 = response.data || [];
          this.psYjsFilesNow = [];
          if (Number(this.tabValue) > 2 && this.data2.length > 0) {
            this.$api.kpzh.review.getByTeamIdAndBusinessId(this.objId, this.data2[0].teamId).then(res => {
              getFiles(res.data.id).then((res) => {
                const files = {}
                res.data.forEach((item) => {
                  if (!files[item.moduleKey]) {
                    files[item.moduleKey] = []
                  }
                  files[item.moduleKey].push({
                    name: item.fileName,
                    url: item.fullFilePath,
                    id: item.id,
                    filePath: item.filePath
                  })
                })
                this.psYjsFilesNow = files.dgAndYsPsYjs || [];
              }).catch(e => {
                this.$message.error(e.toString())
              })
            }).catch((e) => {
              this.$message.error(e.toString());
            });
          }
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }

    },
    getList () {
      this.dataLoading = true;
      if (this.objId) {
        this.$api.kpzh.project.getByBusinessId(this.objId).then(response => {
          this.data = response.data;
          this.dataLoading = false;
        }).catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
      }
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
}
</style>
